﻿using BillUpload.Model;
using System;
using System.Collections.Generic;

namespace BillUpload.Util
{
    class BillDetailUtil
    {
        private static Dictionary<String, String> dictTitle = new Dictionary<String, String>() {
            {"门店id", "platShopId"},
            {"订单号", "platOrderId"},
            {"下单时间", "createTime"},
            {"完成时间", "finishTime"},
            {"商家应收款", "finalAmount"},
            {"订单序号", "daySn"},
            {"账单日期", "billDate"},
            {"交易类型","tradeType"}
        };

        private static Dictionary<String, String> dictData = new Dictionary<String, String>();

        public static bool IsReserve(String ColumnName, String ColumnVal)
        {

            if (dictTitle.ContainsKey(ColumnVal))
            {
                //Console.WriteLine(ColumnVal);
                if (!dictData.ContainsKey(ColumnName))
                    dictData.Add(ColumnName, dictTitle[ColumnVal]);
                return true;
            }
            return false;
        }

        public static void FillData(BillDetail detail, String ColumnName, String ColumnVal)
        {
            if (dictData.ContainsKey(ColumnName))
            {

                switch (dictData[ColumnName])
                {
                    case "platShopId":
                        detail.platShopId = ColumnVal;
                        break;
                    case "platOrderId":
                        detail.platOrderId = ColumnVal;
                        break;
                    case "createTime":
                        detail.createTime = ColumnVal;
                        break;
                    case "finishTime":
                        detail.finishTime = ColumnVal;
                        break;
                    case "finalAmount":
                        detail.finalAmount = Double.Parse(ColumnVal);
                        detail.checkoutAmount = detail.finalAmount;
                        break;
                    case "daySn":
                        detail.daySn = ColumnVal.Equals("-") ? 0 : int.Parse(ColumnVal);
                        break;
                    case "billDate":
                        String billDate = DateUtil.ParsedAndPlus(ColumnVal);
                        detail.billDate = billDate;
                        detail.checkoutDate = billDate;
                        break;
                    case "tradeType":
                        detail.tradeType = ColumnVal;
                        break;
                }
            }
        }
    }
}
